package com.stillalive.springtrans.service;

import com.stillalive.springtrans.mapper.LogInfoMapper;
import com.stillalive.springtrans.mapper.UserInfoMapper;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.transaction.interceptor.TransactionAspectSupport;

@Slf4j
@Service
public class LogService {
    @Autowired
    private LogInfoMapper logInfoMapper;

    @Transactional(propagation = Propagation.NESTED)
    public void registerUser(String name, String op){
        logInfoMapper.insertLog(name, op);
        try{
            int err = 10/0;
        }catch(Exception e){
            TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
            log.info("子事务回滚");
        }

        // System.out.println("log end");
    }
}